<template>
    <div id="invoice">
        <yd-tab :callback='invoices'>
            <yd-tab-panel label="个人发票">
                <yd-cell-group style="margin-bottom:0">
                    <yd-cell-item>
                        <span slot="left">名称：</span>
                        <yd-input slot="right" required :show-required-icon='false' v-model="name" ref="nameName" placeholder="请输入名称"></yd-input>
                    </yd-cell-item>
                    <!-- <yd-cell-item>
                            <span slot="left">税号：</span>
                            <yd-input slot="right"  :show-required-icon='false' v-model="paragraph" ref="paragraphName" placeholder="请输入税号"></yd-input>
                        </yd-cell-item> -->
                </yd-cell-group>
            </yd-tab-panel>
            <yd-tab-panel label="企业发票">
                <yd-cell-group style="margin-bottom:0">
                    <yd-cell-item>
                        <span slot="left">单位名称：</span>
                        <yd-input slot="right" required :show-required-icon='false' v-model="names" ref="nameNames" placeholder="请输入单位名称"></yd-input>
                    </yd-cell-item>
                    <yd-cell-item>
                        <span slot="left">税号：</span>
                        <yd-input slot="right" required :show-required-icon='false' v-model="paragraphs" ref="phoneNames" placeholder="请输入税号"></yd-input>
                    </yd-cell-item>
                </yd-cell-group>
            </yd-tab-panel>
        </yd-tab>

        <div class="dangerBtn">
            <yd-button size="large" @click.native="loginInvoices" type="danger">确定</yd-button>
        </div>
    </div>
</template>
<script>

export default {
    name: 'invoice',
    data() {
        return {
            name: '',
            paragraph: '',
            names: '',
            paragraphs: '',
            invoice: '个人发票'
        }
    },
    methods: {
        invoices(label) {
            this.invoice = label;
        },
        loginInvoices() {
            let invCompany = '';
            let invCode = '';
            if (this.invoice == '个人发票') {
                invCompany = this.name;
                invCode = this.paragraph;
            } else {
                invCompany = this.names;
                invCode = this.paragraphs;
            }
            if (invCompany == '') {
                this.$dialog.toast({
                    mes: '名称不可为空',
                    timeout: 600
                });
                return false;
            }
            if (invCode == '' && this.invoice != '个人发票') {
                this.$dialog.toast({
                    mes: '税号不可为空',
                    timeout: 600
                });
                return false;
            }
            let invoice = 1;
            let msg = {
                invState: '1',
                invTitle: this.invoice,
                invCompany: invCompany,
                invCode: invCode
            }
            this.$dialog.loading.open('请稍后...');
            this.$httpAjax.post(this.CONSTANT.wapiBaseUrl + 'invoice/add', msg)
                .then((response) => {
                    this.$router.go(-1);
                    if (response.status == 200) {
                        this.$dialog.loading.close();
                        if (response.data.msg == 'SUCCESS') {
                            this.$dialog.toast({
                                mes: '操作成功',
                                icon: 'success',
                                timeout: 600
                            });
                        } else {
                            this.$dialog.toast({
                                mes: response.data.msg,
                                icon: 'error',
                                timeout: 600
                            });
                        }
                    }
                }).catch((error) => {
                    this.$dialog.loading.close();
                    this.$dialog.toast({
                        mes: '请求错误，请稍后重试',
                        icon: 'error',
                        timeout: 600
                    });
                });
            // this.$router.replace('/purchase');
        }
    }
}
</script>
<style  scoped>
.dangerBtn {
    width: 100%;
    box-sizing: border-box;
    padding: 0 0.25rem;
    height: auto;
    overflow: hidden;
}
</style>